﻿<cfsilent>
	<cfscript>

		event.setArg("pageTitle", "选课管理 - 学费结算");

		termId = event.getArg("TermID");

		academicYear = event.getArg("AcademicYear");
		academicTerm = event.getArg("AcademicTerm");

		studentId = event.getArg("STU");
		chooserId = event.getArg("SCC");
		
		dictAdvice = getProperty("serviceFactory").getBean("senateDictionaryAdvice");
		datetimeAdvice = getProperty("serviceFactory").getBean("datetimeAdvice");
		propertyAdvice = getProperty("serviceFactory").getBean("studentPropertyAdvice");
		
		currentTab = event.getArg("TabID", "labSummary");
		
		targetArgs = structNew();
		passArgs = structNew();
		
		if ( len(studentId) ) {
			structInsert( targetArgs, "STU", studentId );
		}
		if ( len(termId) ) {
			structInsert( targetArgs, "TID", termId );
		}
		
		/* 搜索学生档案 */
		keyword = event.getArg("Keywords", studentId);
		
		rs_student = queryNew("stu_id");
		
		choosenArray = [];
		
		if ( len(keyword) ) {
			sql = "	SELECT
						stu.stu_id,stu.stu_name,clz.cls_name,ss.student_prop
					FROM
						t_student stu INNER JOIN t_class clz ON clz.cls_id = stu.cls_id INNER JOIN t_student_status ss ON ss.stu_id = stu.stu_id
					WHERE
						stu.stu_id LIKE :condition 
						OR
						stu.stu_name LIKE :condition 
					ORDER BY stu.stu_name";
					
			queryObj = new Query(datasource = application.dnsSlave, maxRows = 60 );
			queryObj.addParam(name = "condition", value = keyword & "%", cfsqltype = "cf_sql_varchar");
			rs_student = queryObj.execute(sql = sql).getResult();
			
		}
		
		/* 读取结算状态 */
		/*
			第2位 是否已缴费
			第3位 是否从预交学费中扣除
		*/
		sql = "	SELECT
					i.institute_name,
					SUM(CASE WHEN SUBSTR(sc.choose_prop,2,1) = '1' AND SUBSTR(sc.choose_prop,3,1) = '0' THEN 1 ELSE 0 END) count_sum,
					SUM(CASE WHEN SUBSTR(sc.choose_prop,2,1) = '1' AND SUBSTR(sc.choose_prop,3,1) = '0' THEN c.course_credit ELSE 0 END) credit_sum,
					SUM(CASE WHEN SUBSTR(sc.choose_prop,2,1) = '0' THEN 1 ELSE 0 END) sum_1,
					SUM(CASE WHEN SUBSTR(sc.choose_prop,2,1) = '0' THEN c.course_credit ELSE 0 END) sum_2,
					SUM(CASE WHEN SUBSTR(sc.choose_prop,3,1) = '1' THEN c.course_credit ELSE 0 END) sum_3
				FROM
					t_student_course sc INNER JOIN t_student stu ON stu.stu_id = sc.stu_id INNER JOIN t_class clz ON clz.cls_id = stu.cls_id
					INNER JOIN t_subject sbj ON sbj.sbj_id = clz.sbj_id INNER JOIN t_institute i ON i.institute_id = sbj.institute_id
					INNER JOIN t_course c ON c.cid = sc.cid
				WHERE
					sc.term_id = :termId 
				GROUP BY
					i.institute_name
				ORDER BY
					i.institute_name";

		queryObj = new Query(datasource = application.dnsSlave );
		queryObj.addParam(name = "termId", value = termId, cfsqltype = "cf_sql_char");
		rs_chargeSummary = queryObj.execute(sql = sql).getResult();
		
	</cfscript>
</cfsilent>

<div id="headArea">
	<div class="uiHeader uiHeaderWithImage ptm">
		<div class="clearfix uiHeaderTop">
			<div class="uiHeaderActions rfloat">
				<a class="uiButton" href="<cfoutput>#buildURL('taskClass')#</cfoutput>"><i class="mrs img btnList"></i><span class="uiButtonText">教学任务</span></a>
			</div>
			<div>
				<h2 class="uiHeaderTitle">
					<i class="uiHeaderImage img icon16x16 card"></i>指定学生学费结算
				</h2>
			</div>
		</div>
	</div>
</div>

<div class="UIElement">
	<ul class="senateFirstPage">
		<li>
			<div class="clearfix" id="create">
				<div class="UItab">
					<div class="tabLables">
						<span <cfif currentTab eq "labSummary">class="active"</cfif> id="labSummary" tabTarget="Summary">缴费情况汇总</span>
						<span <cfif currentTab eq "labStudent">class="active"</cfif> id="labStudent" tabTarget="Student">查找学生</span>
						<cfif len(studentId)>
							<span <cfif currentTab eq "labChooseTable">class="active"</cfif> id="labChooseTable" tabTarget="ChooseTable">结算选课学费</span>
						</cfif>
						<cfif len(chooserId)>
							<span <cfif currentTab eq "labChoosenType">class="active"</cfif> id="labChoosenType" tabTarget="ChoosenType">更改修读方式</span>
						</cfif>
					</div>
				</div>
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					$(document).ready(function() {
						
						/* init Tab */
						$("div.tabContent").hide();
						$("div#" + $("div.tabLables span.active").attr("tabTarget")).show();
						
						$("div.tabLables > span").click(function(){
							var $targetID = $(this).attr("tabTarget");
							
							$("div.tabLables span").removeClass("active");
							$(this).addClass("active");
							
							$("div.tabContent").not('[id="' + $targetID + '"]').hide();
							$("div.tabContent#" + $targetID).show();
						});
						
					});
					
					// -->
					//]]>
				</script>
				
				<div id="Summary" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
							<a class="uiButton uiButtonSpecial" href="<cfoutput>#buildURL('chargeListDownloadExcel', {TID=termId})#</cfoutput>"><i class="mrs img btnDownload"></i><span class="uiButtonText">下载欠费清单</span></a>
						</div>
						<h3><cfoutput>#academicYear#-#academicTerm#</cfoutput> 学期 教学成本运行状态</h3>
						<p>下列是当前学期, 该学生所有已选课程的收费情况统计清单.</p>
						<hr/>
					</div>
					
					<table class="UIEditable">
						<thead>
							<tr>
								<td width="18"></td>
								<td>学院</td>
								<td>预收学费(学分)</td>
								<td>已结算(人次)</td>
								<td>已结算(学分)</td>
								<td>未结算(人次)</td>
								<td>未结算(学分)</td>
								<td align="right">缴费结算进度</td>
							</tr>
						</thead>
						<tbody>
							<cfset row = 0 />
							<cfloop query="rs_chargeSummary">
								
								<cfset row++ />
								<cfset prog = 100 />
								
								<cfif rs_chargeSummary.credit_sum + rs_chargeSummary.sum_2 gt 0>
									<cfset prog = 100 * rs_chargeSummary.credit_sum/(rs_chargeSummary.credit_sum + rs_chargeSummary.sum_2) />
								</cfif>
								
								<!--- 修正白分化的四舍五入  --->
								<cfif prog gt 99.9 and prog lt 100>
									<cfset prog = 99.9 />
								</cfif>

								<tr class="editRows">
									<td><span class="index"><cfoutput>#row#</cfoutput></span></td>
									<td><cfoutput>#rs_chargeSummary.institute_name#</cfoutput></td>
									<td><span class="numeric"><cfoutput>#numberFormat( rs_chargeSummary.sum_3, '_.__')#</cfoutput></span></td>
									<td><span class="numeric bold"><cfoutput>#rs_chargeSummary.count_sum#</cfoutput></span></td>
									<td><span class="numeric"><cfoutput>#numberFormat( rs_chargeSummary.credit_sum, '_.__')#</cfoutput></span></td>
									<td><span class="numeric bold"><cfoutput>#rs_chargeSummary.sum_1#</cfoutput></span></td>
									<td><span class="numeric"><cfoutput>#numberFormat( rs_chargeSummary.sum_2, '_.__')#</cfoutput></span></td>
									<td align="right"><span class="smallNum"><cfoutput>#numberformat(prog, "__._")#</cfoutput>%</span></td>
								</tr>
							</cfloop>
						</tbody>
					</table>
					
				</div>
				
				<div id="Student" class="tabContent">
				
					<form id="formSearch" onSubmit="javascript:return processVerfiyForm('formSearch');" class="formWrapper Transparent" method="post" action="<cfoutput>#buildURL('chargeStudentCourse')#</cfoutput>">
						<input type="hidden" name="TabID" value="labStudent" />
						
						<div class="label">
							<b>学号或姓名</b>
							<input name="Keywords" id="Keywords" type="text" class="typeText" verification="required" maxlength="128" value="<cfoutput>#event.getArg('Keywords')#</cfoutput>" />
						</div>
						<hr/>
						<div class="lable">
							<input class="button1" type="submit" value="搜索" />
						</div>
					</form>
					
					<cfif rs_student.recordCount>
						
						<cfset structInsert( passArgs, "TabID", "labChooseTable", true ) />

						<div class="clearfix">
							<div class="UICardTable">
                                <cfloop query="rs_student">
									
									<cfset structInsert(passArgs, "STU", rs_student.stu_id, true) />
									<cfset propertyAdvice.parseProperty(rs_student.student_prop) />
									
									<dl <cfif not propertyAdvice.getInSchool()>class="disabled"</cfif>>
										<dt>
											<a href="<cfoutput>#buildURL('chargeStudentCourse', passArgs)#</cfoutput>">
												<em class="people"><!--imgholder--></em>
												<dd>
													<h3><cfoutput>#rs_student.stu_name#</cfoutput> - <cfoutput>#rs_student.cls_name#</cfoutput></h3>
													<p><cfoutput>#rs_student.stu_id#</cfoutput></p>
												</dd>
											</a>
										</dt>
									</dl>
								</cfloop>					
							</div>
						</div>
					
					</cfif>
				
				</div>

				<div id="ChooseTable" class="tabContent">
					
					<div class="noticeBlock">
						<div class="operation">
						</div>
						<h3><cfoutput>#academicYear#-#academicTerm#</cfoutput> 学期 学生选课情况</h3>
						<p>下列是该轮次选课安排中, 该学生所有已选课程的清单.</p>
						<hr/>
					</div>
					
					<div id="choosenCourse">
						<!--- 显示选课记录--->
						<!-- choosenCourse -->
						<cfoutput>#event.getArg("choosenCourse")#</cfoutput>
						<!-- /choosenCourse -->
					</div>
					
				</div>
				
				<script language="javascript" type="text/javascript">
					//<![CDATA[
					<!--
					
					function cancelCheckTask(chooserId, courseId, stuId, termId, taskType, taskId) {
						
						/* 显示阻挡信息 */
						$.blockUI({ 
									message: '正在取消课程结算状态...',
									css: { 
											'width': '16%',
											'left': '42%',
											'border': 'none', 
											'padding': '15px 5px', 
											'backgroundColor': '#090', 
											'border-radius': '4px', 
											'opacity': .8, 
											'color': '#fff',
											'cursor': null
											},
									overlayCSS: {
											'backgroundColor': '#000', 
											'opacity': .1 ,
											'cursor': null
											}
									});
						
						/* 异步提交取消选课结算数据 */
						$.post(
								"<cfoutput>#buildURL('apiCancelChargeTask')#</cfoutput>", 
								{
									'STU': stuId,
									'TID': termId,
									'CID' : courseId,
									'TSK': taskId,
									'TT' : taskType,
									'SCC' : chooserId,
									'seed': (new Date()).getTime()
								},
								function(data) {
										
									//$("#out").html(data);
									result = $.parseJSON(data);
									
									if ( result.success ) {
										
										/* 更新学生选课记录 */
										$.post(
												"<cfoutput>#buildURL('apiChargeTaskList')#</cfoutput>", 
												{
													'TID': '<cfoutput>#termId#</cfoutput>',
													'STU': '<cfoutput>#studentId#</cfoutput>',
													'seed': (new Date()).getTime()
												},
												function(tableData) {
												
													$("#choosenCourse").html(tableData);
														
													/* 取消阻挡 */
													$.unblockUI();
														
												});
									}
									else {
										alert(result.reason);
										/* 取消阻挡 */
										$.unblockUI();
									}
										
								});
						
					}
					
					function checkOutTask(chooserId, courseId, stuId, termId, taskType, taskId) {
						
						/* 显示阻挡信息 */
						$.blockUI({ 
									message: '正在结算课程...',
									css: { 
											'width': '16%',
											'left': '42%',
											'border': 'none', 
											'padding': '15px 5px', 
											'backgroundColor': '#F90', 
											'border-radius': '4px', 
											'opacity': .8, 
											'color': '#fff',
											'cursor': null
											},
									overlayCSS: {
											'backgroundColor': '#000', 
											'opacity': .1 ,
											'cursor': null
											}
									}); 
									
						/* 异步提交选课结算数据 */
						$.post(
								"<cfoutput>#buildURL('apiChargeTask')#</cfoutput>", 
								{
									'STU': stuId,
									'TID': termId,
									'CID' : courseId,
									'TSK': taskId,
									'TT' : taskType,
									'SCC' : chooserId,
									'seed': (new Date()).getTime()
								},
								function(data) {
										
									//$("#out").html(data);
									result = $.parseJSON(data);
									
									if ( result.success ) {
										
										/* 更新学生选课记录 */
										$.post(
												"<cfoutput>#buildURL('apiChargeTaskList')#</cfoutput>", 
												{
													'TID': '<cfoutput>#termId#</cfoutput>',
													'STU': '<cfoutput>#studentId#</cfoutput>',
													'seed': (new Date()).getTime()
												},
												function(tableData) {
												
													$("#choosenCourse").html(tableData);
														
													/* 取消阻挡 */
													$.unblockUI();
														
												});
									}
									else {
										alert(result.reason);
										/* 取消阻挡 */
										$.unblockUI();
									}
										
								});
										
						
					}
					// -->
					//]]>
				</script>
				
				<cfif len(chooserId)>
					
                    <cfset sql = "	SELECT
										sc.scc_id,sc.stu_id,sc.term_id,c.course_name,c.course_code,
										c.course_credit,stu.stu_name,sbj.sbj_name,clz.grade,sc.st,sc.retaking
									FROM
										t_student_course sc
										INNER JOIN t_course c ON sc.cid = c.cid
										INNER JOIN t_student stu ON sc.stu_id = stu.stu_id
										INNER JOIN t_class clz ON stu.cls_id = clz.cls_id
										INNER JOIN t_subject sbj ON clz.sbj_id = sbj.sbj_id
									WHERE
										sc.scc_id = :chooserId " />
                    
                    <cfset queryObj = new Query(datasource = application.dnsSlave) />
                    <cfset queryObj.addParam(name = "chooserId", value = chooserId, cfsqltype = "cf_sql_varchar")/>
                    <cfset rs_student_course = queryObj.execute(sql = sql).getResult() />
					
                    <cfif rs_student_course.recordCount>
					
						<div id="ChoosenType" class="tabContent">
					
							<div class="noticeBlock">
								<h3><cfoutput>#academicYear#-#academicTerm#</cfoutput> 学期 调整课程修读方式</h3>
								<p>下列是该学生当前要调整修读方式的课程. 在调整修读方式同时, 系统会自动调整学费的缴纳方式.</p>
								<hr/>
							</div>
					
							<form id="formEdit" onSubmit="javascript:return processVerfiyForm('formEdit');" class="formWrapper" method="post" action="<cfoutput>#buildURL('chargeChoosenStudyTypeDo')#</cfoutput>">
								
								<input name="ChooseID" type="hidden" value="<cfoutput>#rs_student_course.scc_id#</cfoutput>" />
								<input name="StudentID" type="hidden" value="<cfoutput>#rs_student_course.stu_id#</cfoutput>" />
								<input name="TermID" type="hidden" value="<cfoutput>#rs_student_course.term_id#</cfoutput>" />

								<div class="label">
									<b>课程</b>
									<cfoutput>#rs_student_course.course_name#</cfoutput> <cfif len(rs_student_course.course_code)>[<cfoutput>#rs_student_course.course_code#</cfoutput>]</cfif>
								</div>
								
								<div class="label">
									<b>学分</b>
									<cfoutput>#numberFormat(rs_student_course.course_credit, "_.__")#</cfoutput>
								</div>
								
								<div class="label">
									<b>学生</b>
									<cfoutput>#rs_student_course.stu_name#</cfoutput>
								</div>
								
								<div class="label">
									<b>专业班级</b>
									<cfoutput>#rs_student_course.sbj_name#</cfoutput>专业
									<cfoutput>#rs_student_course.grade#</cfoutput>级
								</div>
								
								<div class="label">
									<b>修读方式</b>
									<input name="StudyType" value="N" type="radio" class="typeRadio" <cfif rs_student_course.st eq "N">checked="checked"</cfif> />正常
									<input name="StudyType" value="R" type="radio" class="typeRadio" <cfif rs_student_course.st eq "R">checked="checked"</cfif>/>重新学习 &nbsp;&nbsp;
									<input name="StudyType" value="F" type="radio" class="typeRadio" <cfif rs_student_course.st eq "F">checked="checked"</cfif>/>补修 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									
									<input name="StudyType" value="S" type="radio" class="typeRadio" <cfif rs_student_course.st eq "S">checked="checked"</cfif>/>双学位 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
									<input name="StudyType" value="A" type="radio" class="typeRadio" <cfif rs_student_course.st eq "A">checked="checked"</cfif>/>辅修
									<p class="notice">
										重新学习: 正常修读课程未合格或需要再次修读课程以提高课程成绩. <br/>
										补修: 学籍异动学生可跟班修读培养方案的低年级课程. 若之前学期存在漏选课的学生, 也可申请跟班修读. <br/>
										双学位、辅修: 申请辅修专业或双学位学生选择修读额外专业课程
									</p>
								</div>
								
								<div class="label">
									<b>重修标记</b>
									<input id="Retaking" name="Retaking" value="1" type="checkbox" class="typeRadio" <cfif rs_student_course.retaking eq "1">checked="checked"</cfif> />
								</div>
								
								<hr/>
								<div class="lable">
									<input class="button" type="submit" value="更改" />
								</div>

							</form>
							
							<script language="javascript" type="text/javascript">
								//<![CDATA[
								<!--
								$(":radio[name='StudyType']").change(function(){
								
									if ( $(this).attr("checked") && $(this).val() == "R" ) {
										$(":checkbox[name='Retaking']").attr("checked", "checked");
									}
									else {
										$(":checkbox[name='Retaking']").removeAttr("checked");
									}
									
								});
								// -->
								//]]>
							</script>
							
						</div>
						
					</cfif>
				</cfif>
				
			</div>
		</li>
	</ul>
</div>


